package com.hjm.project.terminal.agentTargetInfo.agentTargetInfo.controller;

import java.util.List;

import com.hjm.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.terminal.agentTargetInfo.agentTargetInfo.domain.AgentTargetInfo;
import com.hjm.project.terminal.agentTargetInfo.agentTargetInfo.service.IAgentTargetInfoService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 代理上指标记录明细Controller
 * 
 * @author maker-platform
 * @date 2021-03-02
 */
@Controller
@RequestMapping("/agentTargetInfo/agentTargetInfo")
public class AgentTargetInfoController extends BaseController
{
    private String prefix = "agentTargetInfo/agentTargetInfo";

    @Autowired
    private IAgentTargetInfoService agentTargetInfoService;

    @RequiresPermissions("agentTargetInfo:agentTargetInfo:view")
    @GetMapping()
    public String agentTargetInfo()
    {
        return prefix + "/agentTargetInfo";
    }


    @GetMapping("/hbRecord")
    public String hbRecord()
    {
        return prefix + "/hbRecord";
    }

    /**
     * 查询代理上指标记录明细列表
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentTargetInfo agentTargetInfo)
    {
        startPage();
        List<AgentTargetInfo> list = agentTargetInfoService.selectAgentTargetInfoList(agentTargetInfo);
        return getDataTable(list);
    }


    /**
     * 查询代理上指标记录明细列表
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:list")
    @PostMapping("/list1")
    @ResponseBody
    public TableDataInfo list1(AgentTargetInfo agentTargetInfo) {
        if (StringUtils.isEmpty(agentTargetInfo.getType())) {
            agentTargetInfo.setType("3,4");
        }
        startPage();
        List<AgentTargetInfo> list = agentTargetInfoService.selectAgentTargetInfoList(agentTargetInfo);
        return getDataTable(list);
    }

    /**
     * 导出代理上指标记录明细列表
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:export")
    @Log(title = "代理上指标记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentTargetInfo agentTargetInfo)
    {
        List<AgentTargetInfo> list = agentTargetInfoService.selectAgentTargetInfoList(agentTargetInfo);
        ExcelUtil<AgentTargetInfo> util = new ExcelUtil<AgentTargetInfo>(AgentTargetInfo.class);
        return util.exportExcel(list, "agentTargetInfo");
    }

    /**
     * 新增代理上指标记录明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理上指标记录明细
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:add")
    @Log(title = "代理上指标记录明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentTargetInfo agentTargetInfo)
    {
        return toAjax(agentTargetInfoService.insertAgentTargetInfo(agentTargetInfo));
    }

    /**
     * 修改代理上指标记录明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        AgentTargetInfo agentTargetInfo = agentTargetInfoService.selectAgentTargetInfoById(id);
        mmap.put("agentTargetInfo", agentTargetInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理上指标记录明细
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:edit")
    @Log(title = "代理上指标记录明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentTargetInfo agentTargetInfo)
    {
        return toAjax(agentTargetInfoService.updateAgentTargetInfo(agentTargetInfo));
    }

    /**
     * 删除代理上指标记录明细
     */
    @RequiresPermissions("agentTargetInfo:agentTargetInfo:remove")
    @Log(title = "代理上指标记录明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(agentTargetInfoService.deleteAgentTargetInfoByIds(ids));
    }
}
